package org.dromara.system.service.impl;

import org.dromara.system.service.SysConfigService;
import org.dromara.system.pojo.entity.SysConfigDO;
import org.dromara.system.pojo.bo.SysConfigBO;
import org.dromara.system.pojo.qo.SysConfigQO;
import org.dromara.system.pojo.vo.SysConfigVO;
import org.dromara.system.mapper.SysConfigMapper;
import org.springframework.stereotype.Service;

import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.utils.BeanCopyUtils;

import java.util.List;

/**
 * 参数配置表 服务层实现。
 *
  * @author mkj
  * @since 2024-07-21
 */
@RequiredArgsConstructor
@Service
public class SysConfigServiceImpl  implements SysConfigService {

    private final SysConfigMapper sysConfigMapper;

    @Override
    public boolean add(SysConfigBO sysConfigBO) {
        SysConfigDO sysConfigDO = BeanCopyUtils.copy(sysConfigBO, SysConfigDO.class);
        return sysConfigMapper.insert(sysConfigDO) > 0;
    }

    @Override
    public boolean remove(Long id) {
        return sysConfigMapper.deleteById(id) > 0;
    }

    @Override
    public boolean update(SysConfigBO sysConfigBO) {
        SysConfigDO sysConfigDO = BeanCopyUtils.copy(sysConfigBO, SysConfigDO.class);
        return sysConfigMapper.update(sysConfigDO) > 0;
    }

    @Override
    public List<SysConfigVO> list(SysConfigQO sysConfigQO) {
        SysConfigDO sysConfigDO = BeanCopyUtils.copy(sysConfigQO, SysConfigDO.class);
        QueryWrapper queryWrapper = QueryWrapper.create(sysConfigDO);
        return sysConfigMapper.selectListByQueryAs(queryWrapper, SysConfigVO.class);
    }

    @Override
    public SysConfigVO getInfo(@PathVariable Long id) {
        SysConfigDO sysConfigDO = sysConfigMapper.selectOneById(id);
        if (sysConfigDO == null){
            return null;
        }
        return BeanCopyUtils.copy(sysConfigDO, SysConfigVO.class);
    }

    @Override
    public Page<SysConfigVO> page(SysConfigQO page) {
        return sysConfigMapper.paginateAs(page.getPageNumber(), page.getPageSize(), QueryWrapper.create(page), SysConfigVO.class);
    }

}

